// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db =cloud.database();
const _ =db.command;


// 云函数入口函数
exports.main = async (event, context) => {
  var id=event.project._id;
  var donatedMoney =event.donatedMoney;
  var credit=event.credit;
  await db.collection("project").doc(id).
  update({
    data: {
      quantity: _.inc(1)
    },
  });

  return res =await db.collection("donor").doc("f18e14fa6543438604a4c12e76abaa0f")
  .update({
    data: {
      //根据 物品价格*0.5*credit
      credit : _.inc(credit),
      times : _.inc(1),
      ['totalDonation.nov']: _.inc(donatedMoney),
    }
  });





}